/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.CompanyInfo;
/*     */ import com.newcrm.bean.Group;
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.CustomerManager;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractAction;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import net.sf.json.JSONObject;
/*     */ import org.apache.commons.lang.time.DateUtils;
/*     */ 
/*     */ public class ShowContactCustomerNumFlow extends AbstractAction
/*     */ {
/*     */   public ShowContactCustomerNumFlow(AbstractHttpServlet servlet)
/*     */   {
/*  35 */     super(servlet);
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException, NotFoundException
/*     */   {
/*  41 */     User user = super.getLoginUser(request);
/*     */ 
/*  43 */     CompanyInfo company = super.getCompany(request);
/*     */ 
/*  45 */     String userId = Util.getURLParameter(request.getParameter("userId"));
/*  46 */     String originalGroupId = Util.getURLParameter(request
/*  47 */       .getParameter("groupId"));
/*  48 */     int groupId = Util.getURLIntParameter(request.getParameter("groupId"));
/*     */ 
/*  51 */     if (((originalGroupId == null) || (originalGroupId.trim().length() == 0)) && (
/*  52 */       (userId == null) || (userId.trim().length() == 0))) {
/*  53 */       if ((!user.isAdmin) && (!user.isGroupAdmin())) {
/*  54 */         userId = user.userId;
/*     */       }
/*  57 */       else if (user.isAdmin) {
/*  58 */         groupId = 0;
/*     */       }
/*     */ 
/*     */     }
/*     */ 
/*  63 */     response.setContentType("text/html;charset=utf-8");
/*  64 */     PrintWriter out = response.getWriter();
/*  65 */     JSONObject jsonObject = new JSONObject();
/*  66 */     CustomerManager customerManager = new CustomerManager();
/*  67 */     int step = 7;
/*  68 */     int[] nums = new int[step];
/*  69 */     int[] nums2 = new int[step];
/*  70 */     String[] days = new String[step];
/*  71 */     Date today = new Date();
/*  72 */     for (int i = 0; i < step; i++) {
/*  73 */       nums[i] = 0;
/*  74 */       nums2[i] = 0;
/*  75 */       days[i] = Util.date2Str2(DateUtils.addDays(today, step - 1 - i));
/*     */     }
/*     */ 
/*  78 */     List result = null;
/*  79 */     List result2 = null;
/*     */     Group group;
/*  80 */     if ((userId != null) && (userId.trim().length() > 0)) {
/*  81 */       result = customerManager.getLastContactCustomerNum(user.companyId, 
/*  82 */         userId, step);
/*     */ 
/*  84 */       result2 = customerManager.getCreateCustomerNum(user.companyId, 
/*  85 */         userId, step);
/*     */     } else {
/*  87 */       String groupIds = "";
/*     */ 
/*  89 */       if (groupId == 0) {
/*  90 */         groupIds = "";
/*     */       } else {
/*  92 */         group = company.getGroupById(groupId);
/*  93 */         if (group != null)
/*  94 */           groupIds = group.getAllIds();
/*     */         else {
/*  96 */           groupIds = String.valueOf(user.groupId);
/*     */         }
/*     */       }
/*     */ 
/* 100 */       result = customerManager.getLastContactCustomerNumByGroupIds(
/* 101 */         user.companyId, groupIds, step);
/* 102 */       result2 = customerManager.getCreateCustomerNumByGroupIds(
/* 103 */         user.companyId, groupIds, step);
/*     */     }
/*     */ 
/* 106 */     if (result != null) {
/* 107 */       for (Object itemO : result) {
                    Map item = (Map)itemO;
/* 108 */         int k = Util.str2Int(item.get("diffdate"));
/* 109 */         int num = Util.str2Int(item.get("Nums"));
/* 110 */         if ((k >= 0) && (k < step)) {
/* 111 */           nums[(step - k - 1)] = num;
/*     */         }
/*     */       }
/*     */     }
/*     */ 
/* 116 */     if (result2 != null) {
/* 117 */       for (Object itemO : result2) {
                    Map item = (Map)itemO;
/* 118 */         int k = Util.str2Int(item.get("diffdate"));
/* 119 */         int num = Util.str2Int(item.get("Nums"));
/* 120 */         if ((k >= 0) && (k < step)) {
/* 121 */           nums2[(step - k - 1)] = num;
/*     */         }
/*     */       }
/*     */ 
/*     */     }
/*     */ 
/* 127 */     jsonObject.put("error", Integer.valueOf(0));
/* 128 */     jsonObject.put("contactNums", nums);
/* 129 */     jsonObject.put("createNums", nums2);
/* 130 */     jsonObject.put("days", days);
/* 131 */     out.println(jsonObject);
/* 132 */     out.flush();
/* 133 */     out.close();
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.ShowContactCustomerNumFlow
 * JD-Core Version:    0.6.1
 */